package com.fancy.learncenter.ui.view;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.widget.CardView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fancy.learncenter.R;
import com.fancy.learncenter.common.MyApplication;
import com.fancy.learncenter.ui.activity.base.MallCommonH5Activity;

/**
 * Created by Hyy on 2017/3/10.
 */

public class UpdataAPKPopupWindow extends BasePopupWindow {
    View popopView;

    View locationView;

    Activity mContext;

    ImageView close;

    TextView title;
    TextView content;
    TextView confirm;

    private CardView ll_popup;


    String strTitle;
    String strContent;
    String strUpUrl;

    public UpdataAPKPopupWindow(Activity mContext, View locationView, String strTitle, String strContent, String strUpUrl) {
        super(mContext);
        this.mContext = mContext;
        this.locationView = locationView;
        this.strTitle = strTitle;
        this.strContent = strContent;
        this.strUpUrl = strUpUrl;

        popopView = LayoutInflater.from(MyApplication.context).inflate(R.layout.popupwindow_updata, (ViewGroup) locationView, false);
        ll_popup = (CardView) popopView.findViewById(R.id.ll_popup);


        close = (ImageView) popopView.findViewById(R.id.colse_icon);
        title = (TextView) popopView.findViewById(R.id.title);
        content = (TextView) popopView.findViewById(R.id.content);
        confirm = (TextView) popopView.findViewById(R.id.confirm);


        title.setText(strTitle);
        content.setText(strContent);
        initPopupWionw();

    }

    private void initPopupWionw() {

        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);

        setOutsideTouchable(false);

        setContentView(popopView);

        popopView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                dismiss();
            }
        });
        ll_popup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, MallCommonH5Activity.class);
                intent.putExtra(MallCommonH5Activity.URL_KEY, strUpUrl);
                mContext.startActivity(intent);
            }
        });


        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }


    @Override
    public void showPopupWindow() {
        super.showPopupWindow();

        showAtLocation(locationView, Gravity.CENTER, 0, 0);
    }

    public void setCloseHide() {
        close.setVisibility(View.GONE);
    }
}
